package ammonite.integration
import ammonite.util.Util
import utest._
import TestUtils._

/**
 * Mostly already tested in the `ammonite.main` unit tests; one test case is
 * left here just to verify end-to-end correctness
 */
object LineNumberTests extends TestSuite {
  val tests = this {

    def checkErrorMessage(file: os.RelPath, expected: String): Unit = {
      val e = assertThrows[os.SubprocessException] {
        exec(file)
      }.result.err.text()
      assert(TestUtils.containsLines(e, expected))
    }

    test("compilationErrorInSecondBlock") {
      val path = os.rel / "lineNumbers" / "compilationErrorInSecondBlock.sc"
      val sp = " "
      checkErrorMessage(
        file = path,
        expected = Util.normalizeNewlines(
          if (isScala2)
            """compilationErrorInSecondBlock.sc:14: not found: value printnl
              |val res_0 = printnl("OK")
              |            ^""".stripMargin
          else if (scalaVersion < "3.3.4")
            s"""-- [E006] Not Found Error: ${replStandaloneResources / path}:1:12$sp
               |1 |val res_0 = printnl("OK")
               |  |            ^^^^^^^
               |  |            Not found: printnl
               |Compilation Failed""".stripMargin
          else
            s"""-- [E006] Not Found Error: ${replStandaloneResources / path}:1:12$sp
               |1 |val res_0 = printnl("OK")
               |  |            ^^^^^^^
               |  |    Not found: printnl - did you mean print? or perhaps printf or println?
               |  |
               |  | longer explanation available when compiling with `-explain`
               |Compilation Failed""".stripMargin
        )
      )
    }

  }
}
